import React from 'react';
import { Select, Spin } from 'antd';

import useGradeList from '../../hooks/useGradeList';

// 职级
export default ({ query, value, onChange, ...rest }) => {
    const [gradeLoading, gradeList] = useGradeList(query);
    console.log('gradeList', gradeList);

    // 填写初始值
    React.useEffect(() => {
        if (value) onChange(value);
    }, [gradeList]);

    return (
        <Spin spinning={gradeLoading}>
            <Select
                placeholder="请选择"
                value={value}
                onChange={onChange}
                optionFilterProp="children"
                allowClear
                {...rest}
            >
                {gradeList.map(item => (
                    <Select.Option key={item.rankCode} value={item.rankCode}>
                        {item.rankValue}
                        {item.state === 1 ? ' (变更审批中)' : ''}
                        {item.state === 2 ? ' (变更待生效)' : ''}
                    </Select.Option>
                ))}
            </Select>
        </Spin>
    );
};
